<template>
  <div class="techincItem">
    <div class="left">
      <!-- 最多显示两行 van-multi-ellipsis--l2 -->
      <div class="left-top  van-multi-ellipsis--l2">
        {{ info.title }}
      </div>
      <div class="left-bottom">
        <span class="l1">{{ info.updated_at | formatTime }}</span>
        <i class="iconfont l2"> &#xe644; </i>
        <span class="l3">{{ info.read }}</span>
        <i class="iconfont l4"> &#xe638; </i>
        <span class="l5">{{ info.star }}</span>
      </div>
    </div>
    <div>
      <img class="right" v-if="info.cover" :src="baseUrl + info.cover" alt="" />
    </div>
  </div>
</template>

<script>
import moment from 'moment'
export default {
  data () {
    return {
      baseUrl: process.env.VUE_APP_URL
    }
  },
  /* 通过props接收数据 */
  props: {
    info: {
      type: Object
    }
  },
  /* 定义一个formatTime时间过滤器 */
  filters: {
    formatTime (val) {
      const _diff = moment().diff(moment(val), 'h') //h===hours
      if (_diff < 1) {
        return '刚刚'
      } else if (_diff >= 1 && _diff < 11540) {
        return _diff + '小时前'
      } else {
        return moment(val).format('YYYY/MM/DD HH:mm:ss')
      }
    }
  }
}
</script>

<style lang="less" scoped>
.techincItem {
  display: flex;
  align-items: space-between;
  .left {
    flex: 1;
    display: flex;
    align-self: stretch;
    /* 改变flex主轴方向 */
    flex-direction: column;
    /*主轴方向两端对齐  */
    justify-content: space-between;
    .left-top {
      font-size: 16px;
      font-family: PingFangSC, PingFangSC-Medium;
      font-weight: 600;
      text-align: left;
      color: #181a39;
      line-height: 22px;
      letter-spacing: 0px;
    }
    .left-bottom {
      margin-bottom: 20px;
      margin-top: 15px;
      display: flex;
      font-size: 12px;
      color: #b4b4bd;
      align-items: center;
    }
    .l1 {
      flex: 1;
    }
    .l3 {
      margin-right: 15px;
    }
  }
  .right {
    width: 113px;
    height: 75px;
    /* 相片不变形 */
    object-fit: contain;
    margin-left: 10px;
  }
}
</style>
